//
//  StoreCell.m
//  NPS
//
//  Created by jadd on 15/10/12.
//  Copyright © 2015年 jadd. All rights reserved.
//

#import "StoreCell.h"
#define kWidth 19
#define kHeight 24
#define Size14 14

@implementation StoreCell

@synthesize QRcodeBtn;
@synthesize modofyBtn;

@synthesize nameLabel;

@synthesize recommendLabel;
@synthesize dailyAddLabel;
@synthesize satLabel;
@synthesize dailyAdd;

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //NSLog(@"%f",(K_ScreenWidth/320)*10);
        nameLabel = [[UILabel alloc] initWithFrame:CGRectMake((K_ScreenWidth/320)*10, 10, 220, 25)];
        nameLabel.adjustsFontSizeToFitWidth = YES;
        nameLabel.font = [UIFont systemFontOfSize:18];
        [self.contentView addSubview:nameLabel];
        
        //下划线
        UIView *lineVw = [[UIView alloc] initWithFrame:CGRectMake((K_ScreenWidth/320)*10, 50, (K_ScreenWidth-10), 1)];
        lineVw.backgroundColor = STORE_LINE_COLOR;
        [self.contentView addSubview:lineVw];
        
        recommendLabel = [[UILabel alloc] initWithFrame:CGRectMake((K_ScreenWidth/320)*25, 105, 90, 20)];
        recommendLabel.textColor = Gray;
        recommendLabel.font = [UIFont systemFontOfSize:Size14];
        recommendLabel.text = @"本周推荐指数";
        [self.contentView addSubview:recommendLabel];
        
        
        recommendLabel = [[UILabel alloc] initWithFrame:CGRectMake((K_ScreenWidth/320)*20, 55, 100, 50)];
        recommendLabel.textAlignment = NSTextAlignmentCenter;
        recommendLabel.adjustsFontSizeToFitWidth = YES;
        [self addSubview:recommendLabel];
        
        
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        satLabel = [[UILabel alloc] initWithFrame:CGRectMake((K_ScreenWidth/320)*130, 105, 90, 20)];
        satLabel.textColor = Gray;
        satLabel.font = [UIFont systemFontOfSize:Size14];
        satLabel.text = @"本周满意度";
        [self.contentView addSubview:satLabel];
        

        satLabel = [[UILabel alloc] initWithFrame:CGRectMake((K_ScreenWidth/320)*120, 55, 100, 50)];
        satLabel.textAlignment = NSTextAlignmentCenter;
        satLabel.adjustsFontSizeToFitWidth = YES;
        [self addSubview:satLabel];
        
        
        dailyAddLabel = [[UILabel alloc] initWithFrame:CGRectMake((K_ScreenWidth/320)*230, 105, 85, 20)];
        dailyAddLabel.textColor = Gray;
        dailyAddLabel.font = [UIFont systemFontOfSize:Size14];
        dailyAddLabel.text = @"今日填写量";
       
        [self.contentView addSubview:dailyAddLabel];
        
        dailyAdd = [[UILabel alloc] initWithFrame:CGRectMake((K_ScreenWidth/320)*225, 55, 90, 50)];
        dailyAdd.textColor = BLACK;
        dailyAdd.textAlignment = NSTextAlignmentCenter;
        dailyAdd.font = [UIFont systemFontOfSize:35];
        dailyAdd.text = @"150";dailyAdd.adjustsFontSizeToFitWidth = YES;
        
        [self.contentView addSubview:dailyAdd];
        
        /*
        modofyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [modofyBtn.imageView setContentMode:UIViewContentModeScaleAspectFit];
        modofyBtn.frame = CGRectMake((K_ScreenWidth/320)*240, 10, 32, 32);
        [modofyBtn setBackgroundImage:[UIImage imageNamed:@"bianji"] forState:UIControlStateNormal];
        [self.contentView addSubview:modofyBtn];
        */
        
        QRcodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [QRcodeBtn.imageView setContentMode:UIViewContentModeScaleAspectFit];
        [QRcodeBtn setBackgroundImage:[UIImage imageNamed:@"QR-Code"] forState:UIControlStateNormal];
        QRcodeBtn.frame = CGRectMake((K_ScreenWidth/320)*275, 10, 32, 32);
        [self.contentView addSubview:QRcodeBtn];
    
    }
    return self;
}

-(void) buttonAction:(UIButton *)sender
{
    if(self.btn_click)
    {
        self.btn_click();
    }
}


-(NSString *)getImage:(NSUInteger)index
{
    switch (index) {
        case 101:
            return @"blue-down";
            break;
        case 100:
            return @"blue-up";
            break;
        case 201:
            return @"green-down";
            break;
        case 200:
            return @"green-up";
            break;
        default:
            return @"";
            break;
    }
}

-(NSAttributedString *) setNSAttributedString:(NSString *)string Index:(NSUInteger) index TextColor:(UIColor *)color
{
    
    NSUInteger length = string.length;
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:string];
    
    // 修改富文本中的不同文字的样式
    [attri addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0, length)];
    [attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:35] range:NSMakeRange(0, length)];
    
    NSTextAttachment *attchs = [[NSTextAttachment alloc] init];
    attchs.image = [UIImage imageNamed:[self getImage:index]];
    attchs.bounds = CGRectMake(0, 0, 10, 18);
    
    // 创建带有图片的富文本
    NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attchs];
    [attri appendAttributedString:str];
    
    // 用label的attributedText属性来使用富文本
    return attri;
}

- (void)setLabelText:(StoreModel *) model
{
    nameLabel.text = model.name;
    
    NSUInteger recStyle = model.recommendTrend == 1 ? 100 : 101;
    if(model.recommendTrend == 2)
    {
        recStyle = 203;
    }
    recommendLabel.attributedText = [self setNSAttributedString:model.recommend Index:recStyle TextColor:TEXT_COLOR_Commend];
    NSUInteger satStyle = model.satTrend == 1 ? 200 : 201;
    if(model.satTrend == 2)
    {
        satStyle = 203;
    }
    satLabel.attributedText = [self setNSAttributedString:model.sat Index:satStyle TextColor:TEXT_COLOR_Sat];
    dailyAdd.text = model.rspd;
    

}
@end
